<template>
    <div>
        <ul class="clearfix" style="margin-bottom: 70px;">
            <li class="clearfix address-li b-g-f" v-for="(item,index) in addList" :key="index">
                <span class="address-name-phone">收货人：{{item.name}} <em class="address-phone">{{item.tel}}</em></span>
                <span class="address-xx">{{item.address_all}}</span>
                <span class="address-bj" :class="item.is_default == 1 ? 'moren' : ''">
                    <img v-if="item.is_default == 1" src="../../../static/img/mr-address.png" alt="">
                    <img v-else src="../../../static/img/kong.png" alt="" @click="addSertDefault(item.id)">默认地址
                    <em class="address-bi" @click="detele(item.id)"><img src="../../../static/img/delete.png" alt="">删除</em>
                    <em class="address-bi" @click="editor(item)"><img src="../../../static/img/bi.png" alt="">编辑</em>
                </span>
            </li>
        </ul>
        <div class="null-gwc" style="display:none;">
            <img src="../../../static/img/dizhi.png" alt="">
            <span class="gwc-tit">您还没有添加地址哦~</span>
        </div>
        <div class="add-address" @click="add()">
            添加新地址
        </div>
    </div>
</template>
<script>
import { Dialog, Toast } from 'vant'
export default {
    data(){
        return{
            addList:[],
        }
    },
    mounted(){
        this.addressIndex()
    },
    methods:{
        // 地址列表
        addressIndex(){
            this.$api.shopping.addressIndex().then(resp=>{
                if(resp.code == 1){
                    this.addList = resp.data
                }
            })
        },
        // 编辑地址
        editor(item){
            this.$router.push({
                name:'addAddress',
                query:{
                    address:JSON.stringify(item)
                }
            })
        },
        // 设置默认地址
        addSertDefault(id){
            this.$api.shopping.addSertDefault({addr_id:id}).then(resp=>{
                if(resp.code == 1){
                    Toast('设置成功')
                    this.addressIndex()
                }
            })
        },
        // 删除地址
        detele(id){
            Dialog.confirm({ 
                title: '标题',
                message: '您确定要删除地址吗？',
                confirmButtonText:'取消',
                cancelButtonText:'确定'
            }).then(() => {
                // on confirm
            }).catch(() => {
                this.$api.shopping.addDeladdr({addr_id:id}).then(resp=>{
                    if(resp.code == 1){
                        Toast(resp.msg)
                        this.addressIndex()
                    }else{
                        Toast(resp.msg)
                    }
                })
            });
        },
        // 添加地址页面跳转
        add(){
            this.$router.push({
                name:'addAddress'
            })
        }
    }
}
</script>

<style lang="less" scoped>
.address-li{
    border-top: 20px solid #f5f5f5;
    padding: 30px;
    .address-name-phone{
        font-size: 40px;
        height: 80px;
        line-height: 80px;
        display: block;
        .address-phone{
            float: right;
        }
    }
    .address-xx{
        font-size: 34px;
        color: #666;
        display: block;
        text-align: justify;
        line-height: 55px;
        border-bottom: 2px #f5f5f5 solid;
        padding-bottom: 10px;
    }
    .moren{
        color: #5CA1EE;
    }
    .address-bj{
        height: 90px;
        line-height: 120px;
        display: block;
        overflow: hidden;
        img{
            width: 30px;
            height: 30px;
            margin-right: 10px;
            float: left;
            margin-top: 43px;
        }
        .address-bi{
            float: right;
            color: #333;
            margin-left: 50px;
            img{
                width: 30px;
                height: 32px;
                margin-right: 20px;
                vertical-align: middle;
            }
        }
    }
}
</style>

